<?php include_once "head.php"?>
<table class="layui-table">
    <thead>
    <tr>
        <th>id</th>
        <th>名称</th>
        <th>添加时间</th>
        <th>修改时间</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody>
    <?php if(!empty($data)){
        foreach($data as $k=>$v){
            ?>
            <tr>
                <td><?=$v['id']?></td>
                <td><?=$v['name']?></td>
                <td><?=$v['add_time']?></td>
                <td><?=$v['update_time']?></td>
                <td>
                    <input type="hidden" name="" value="<?=$v['name']?>" class="old_name<?=$k+1?>">
                    <input type="hidden" name="" value="<?=$v['id']?>" class="id<?=$k+1?>">
                    <button class="layui-btn layui-btn-xs edit<?=$k+1?>">编辑</button>
                    <button class="layui-btn layui-btn-xs layui-btn-danger del<?=$k+1?>">删除</button>
                </td>
            </tr>
        <?php }} ?>

    </tbody>
</table>




<script>
    //定义一个100的jquery数组
    var arr=[];
    for(var i=1;i<101;i++){
        arr.push(i)
    }
    $.each(arr,function(i,n){

        //编辑
        $(".edit"+n).click(function(){
            html1="";
            html1+="<div class=\"layui-form-item\">";
            html1+="<label class=\"layui-form-label\">修改拜年对象</label>";
            html1+="<div class=\"layui-input-inline\">";
            html1+="<input type=\"text\" name=\"title\" value=\"\" placeholder=\"请输入修改拜年对象名称\" class=\"layui-input edit_name\">";
            html1+="</div>";
            html1+="<div class=\"layui-form-mid layui-word-aux\">不能大于10个字</div>";
            html1+="</div>";
            layer.open({
                title:"修改拜年对象"
                ,content:html1
                ,area: ['500px', '200px']
                ,btn: ['确认', '取消']
                ,yes: function(index, layero){
                    //按钮【按钮一】的回调
                    var edit_name=$(".edit_name").val();
                    var old_name=$(".old_name"+n).val();
                    var id=$(".id"+n).val();
                    $.ajax({
                        type: "post",
                        data: {edit_name:edit_name,old_name:old_name,id:id},
                        dataType: "json",
                        url: "<?=base_url("activity/wangchun/save_edit_select_person")?>",
                        success: function (res) {
                            if(res.code==0){
                                layer.msg(res.msg,{time:2000},function(){
                                    window.location.reload()
                                })

                            }else{
                                layer.msg(res.msg,{time:2000})
                            }
                        }
                    })
                }
                ,btn2: function(index, layero){
                    //按钮【按钮二】的回调

                    //return false 开启该代码可禁止点击该按钮关闭
                }
                ,cancel: function(){
                    //右上角关闭回调

                    //return false 开启该代码可禁止点击该按钮关闭
                }
            });
        })

        //删除
        $(".del"+n).click(function(){
            var id=$(".id"+n).val();
            $.ajax({
                type: "post",
                data: {id:id},
                dataType: "json",
                url: "<?=base_url("activity/wangchun/select_person_del")?>",
                success: function (res) {
                    if(res.code==0){
                        layer.msg(res.msg,{time:2000},function(){
                            window.location.reload()
                        })
                    }else{
                        layer.msg(res.msg,{time:2000})
                    }
                }
            })
        })
    })

    //新增主持人
    $(".add_select_person").click(function(){
        $.ajax({
            type: "get",
            data: {},
            dataType: "json",
            url: "<?=base_url("activity/wangchun/select_add_person")?>",
            success: function (res) {
                if (res.code == 0) {
                    html1="";
                    html1+="<div class=\"layui-form-item\">";
                    html1+="<label class=\"layui-form-label\">添加拜年对象</label>";
                    html1+="<div class=\"layui-input-inline\">";
                    html1+="<input type=\"text\" name=\"title\" value=\"\" placeholder=\"请输入拜年对象名称\" class=\"layui-input host_name\">";
                    html1+="</div>";
                    html1+="<div class=\"layui-form-mid layui-word-aux\">不能大于10个字</div>";
                    html1+="</div>";
                    layer.open({
                        title:"添加拜年对象"
                        ,content:html1
                        ,area: ['500px', '200px']
                        ,btn: ['确认', '取消']
                        ,yes: function(index, layero){
                            //按钮【按钮一】的回调
                            var host_name=$(".host_name").val();
                            $.ajax({
                                type: "post",
                                data: {host_name:host_name},
                                dataType: "json",
                                url: "<?=base_url("activity/wangchun/save_add_select_person")?>",
                                success: function (res) {
                                    if(res.code==0){
                                        layer.msg(res.msg,{time:2000},function(){
                                            window.location.reload()
                                        })

                                    }else{
                                        layer.msg(res.msg,{time:2000})
                                    }
                                }
                            })
                        }
                        ,btn2: function(index, layero){
                            //按钮【按钮二】的回调

                            //return false 开启该代码可禁止点击该按钮关闭
                        }
                        ,cancel: function(){
                            //右上角关闭回调

                            //return false 开启该代码可禁止点击该按钮关闭
                        }
                    });
                }else{
                    layer.msg(res.msg,{time:2000})
                }
            }
        })


    })
</script>
